/**
 *
 * @author DorcasBless
 * you can find the Synaxarium at http://code.google.com/p/synaxarium/
 * April, 2009
 * Version 1.0.0
 *
 */
package com.christian;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Vector;
import javax.microedition.midlet.MIDlet;

public class FileReader {

    // byte array length = 100000
    private static byte[] b = new byte[100000];

    public static String readText(String fileName, MIDlet midelt) throws IOException {
        String text = null;
        DataInputStream is = null;
        is = new DataInputStream(midelt.getClass().getResourceAsStream(fileName));
        int byteNum = is.read(b);
        text = new String(b, 0, byteNum, "UTF-8");
        is.close();
        return text;
    }

    public static String fillPage(Vector pages, String text) {
        int hashIndex = 0, starIndex = 0;
        String currentTitle, currentSubject;

        hashIndex = text.indexOf('$');
        String copticDate = null;
        if (Character.isDigit(text.charAt(0)))
        {
         copticDate = text.substring(0, hashIndex);
        }
        else
        {
            copticDate = text.substring(1, hashIndex);
        }
        //Character.isDigit(text.charAt(0));

        starIndex = text.indexOf('*', starIndex + 1);
        Page p = null;
        while (starIndex >= 0) {
            currentTitle = text.substring(hashIndex + 1, starIndex);
            hashIndex = text.indexOf("#", starIndex);
            currentSubject = text.substring(starIndex + 1, hashIndex);
            starIndex = text.indexOf('*', starIndex + 1);
            p = new Page();
            p.setTitle(currentTitle);
            p.setSubject(currentSubject);
            pages.addElement(p);
        }
        return copticDate;
    }
}
